package com.liaogui.consumer.controller.sys;

import com.liaogui.common.entity.userinfo.UserInfoEntity;
import com.liaogui.common.service.userinfo.UserInfoService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping("/sys")
public class UserCentController {
    @Reference
    protected UserInfoService userInfoService;
    @RequestMapping("logout")
    public String logout(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "redirect:../login.html";
    }
    @RequestMapping("login")
    public String login(){
        return "login";
    }
    @RequestMapping("index")
    public String index(){
        return "index";
    }
    @RequestMapping("create")
    public String create(){
        return "create";
    }
    @RequestMapping("edit")
    public ModelAndView edit(String id){
        ModelAndView modelAndView = new ModelAndView();
        UserInfoEntity userInfoEntity = userInfoService.getById(id);
        if (userInfoEntity !=null){
            modelAndView.setViewName("edit");
            modelAndView.addObject("userInfo",userInfoEntity);
            return modelAndView;
        }
        modelAndView.addObject("edit");
        return modelAndView;
    }
}
